package com.chexiehui.jc.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.chexiehui.jc.R;
import com.chexiehui.jc.base.BaseActivity;
import com.chexiehui.jc.entity.CarInfo;
import com.chexiehui.jc.ui.fragment.CarBrandParameterAllFragment;
import com.chexiehui.jc.ui.fragment.CarBrandParameterCompareFragment;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * 参数配置
 */
public class CarBrandParameter2Activity extends BaseActivity {

    @BindView(R.id.vp_type_pager)
    ViewPager vpTypePager;
    private SlidingTabLayout stl_car_garage_tab;
    private String[] titles = new String[]{"综合", "参数配置"};
    private ArrayList<Fragment> forumFragmentList = new ArrayList<>();

    private ArrayList<CarInfo> compareList;

    @Override
    protected void beforeSetView() {
        Bundle bundle = getIntent().getExtras();
        if(bundle != null){
            compareList = (ArrayList<CarInfo>) bundle.getSerializable("compareList");
        }
    }

    @Override
    protected void setTitleBar() {
        View centerAction = View.inflate(mContext, R.layout.layout_title_action_car_brand_parameter, null);
        stl_car_garage_tab = centerAction.findViewById(R.id.stl_type_tab);
        titleBar.addCenterAction(titleBar.new ViewAction(centerAction));
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_car_brand_parameter2;
    }

    @Override
    protected void initView(Bundle var1) {
        forumFragmentList = new ArrayList<>();
        vpTypePager.setOffscreenPageLimit(titles.length);
        forumFragmentList.add(CarBrandParameterAllFragment.getInstance());
        forumFragmentList.add(CarBrandParameterCompareFragment.getInstance(compareList));
        stl_car_garage_tab.setViewPager(vpTypePager, titles, this, forumFragmentList);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(forumFragmentList != null && forumFragmentList.size() > 0){
            for (int i = 0; i < forumFragmentList.size(); i++) {
                forumFragmentList.get(i).onActivityResult(requestCode, resultCode, data);
            }
        }
    }
}
